// Package gin
// Created by GoLand
// @User: lenora
// @Date: 2023/11/27
// @Time: 13:50

package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	server := gin.Default()

	// 中间件
	server.Use(func(context *gin.Context) {
		println("that's the first middleware")
	}, func(context *gin.Context) {
		println("that's the second middleware")
	})
	// 静态路由
	server.GET("/hello", func(ctx *gin.Context) {
		ctx.String(http.StatusOK, "hello gin")
	})

	// 参数路由
	server.GET("/users/:name", func(ctx *gin.Context) {
		name := ctx.Param("name")
		ctx.String(http.StatusOK, "hello "+name)
	})

	// 通配符路由
	// 不支持/web/*,/users/*/a这类型的路由,也就是说,*不可以单独出现
	server.GET("/order/*.html", func(ctx *gin.Context) {
		order := ctx.Param(".html")
		ctx.String(http.StatusOK, "order view is  "+order)
	})
	_ = server.Run(":8085")
}
